//
//  CameraView.h
//  XPhoto
//
//  Created by baboy on 2020/5/31.
//  Copyright © 2020 baboy. All rights reserved.
//

#import <UIKit/UIKit.h>

#import <AVFoundation/AVFoundation.h>
#import "BKDialPlateView.h"
#import "VideoRecordProgressView.h"
#import "PhotoAsset.h"

#define CAMERA_MODE_TAKE_PHOTO      1
#define CAMERA_MODE_SHOOT_VIDEO     2

NS_ASSUME_NONNULL_BEGIN
@protocol CameraViewDelegate;
@protocol PhotoThumbListViewDelegate;
@class PhotoThumbListView;

@interface CameraView : UIView

@property (nonatomic, strong) AVCaptureSession *captureSession;
@property (nonatomic, strong) AVCaptureDevice *videoDevice;
@property (nonatomic, strong) AVCaptureDevice *audioDevice;
@property (nonatomic, strong) AVCaptureDeviceInput *videoInput;
@property (nonatomic, strong) AVCaptureDeviceInput *audioInput;
@property (nonatomic, strong) AVCaptureMovieFileOutput *movieFileOutput;
@property (nonatomic, strong) AVCapturePhotoOutput *photoOutput;
@property (nonatomic, strong) AVCaptureVideoPreviewLayer *previewLayer;
@property (nonatomic, strong) AVCaptureConnection *captureConnection;

@property(nonatomic, strong) IBOutlet UIView *bottomPannel;
@property(nonatomic, strong) IBOutlet UIButton *shootButton;
@property(nonatomic, strong) IBOutlet UIButton *devicePositionButton;
@property(nonatomic, strong) IBOutlet UIView *previewView; //预览View
@property(nonatomic, strong) IBOutlet VideoRecordProgressView *videoRecordProgressView; //预览View
@property(nonatomic, strong) IBOutlet UIButton *thumbButton; //左下角缩略图按钮水
@property(nonatomic, strong) IBOutlet UILabel *photoCountLabel;//缩略图上面数量

//视频相关
@property(nonatomic, strong) IBOutlet UIView *timerView; //视频计时
@property(nonatomic, strong) IBOutlet UILabel *timerLabel; //视频计时Label
@property(nonatomic, assign) IBOutlet id<CameraViewDelegate>delegate;




@property(nonatomic, strong) NSString *filePath;
@property(nonatomic, strong) NSMutableArray *photos;
@property(nonatomic, strong) NSMutableArray *videoClips;

@property(nonatomic, assign) NSInteger mode;

- (void)startSession;
- (void)stopSession;
- (void)finishedWithCompletion:(void (^)(NSError *, NSArray *))completion;
@end

@protocol CameraViewDelegate <NSObject>
@required
- (void)cameraViewDidStartRecording:(CameraView*)view;
- (void)cameraView:(CameraView*)view didFinishRecording:(PhotoAsset *)photoAsset;
- (void)cameraView:(CameraView*)view didRemoveVideo:(PhotoAsset *)photoAsset;
- (void)cameraView:(CameraView*)view didFinishProcessingPhoto:(PhotoAsset *)photoAsset;
- (void)cameraView:(CameraView*)view didRemovePhoto:(PhotoAsset *)photoAsset;
- (void)cameraView:(CameraView*)view didTakePhoto:(PhotoAsset *)photoAsset;

@end




@protocol PhotoThumbListViewDelegate <NSObject>
@required
- (void)photoThumbListView:(PhotoThumbListView *)view didRemoveAtIndex:(NSInteger)index withItem:(PhotoAsset *)photoAsset;
- (void)photoThumbListView:(PhotoThumbListView *)view didClickAtIndex:(NSInteger)index withItem:(PhotoAsset *)photoAsset;

@end

@interface PhotoThumbListView : UIView
@property(nonatomic, assign) IBOutlet UIScrollView *contentScrollView;
@property(nonatomic, readonly) NSMutableArray *photos;
@property(nonatomic, readonly) NSMutableArray *itemViews;
@property(nonatomic, assign) IBOutlet id<PhotoThumbListViewDelegate> actionDelegate;

- (void)addPhoto:(PhotoAsset *)photoAsset;
- (void)removePhoto:(PhotoAsset *)photoAsset;
@end

NS_ASSUME_NONNULL_END
